package com.bw.flinkstreaming.source1.job3;

import org.apache.flink.streaming.api.functions.source.ParallelSourceFunction;

public class ParallelSource implements ParallelSourceFunction<Long> {
    private long number = 1L;
    private boolean isRunning = true;

    //模拟数据, -> 从mysql读取，从redis读取
    @Override
    public void run(SourceContext<Long> sourceContext) throws Exception {
        while (isRunning) {
            // sourceContext：将数据写入到下游
            sourceContext.collect(number);
            number++;
            //每个一秒钟产生一条数据
            Thread.sleep(1000);
        }
    }

    @Override
    public void cancel() {
        isRunning = false;
    }
}
